<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue</title>
  <script src="./js/vue.js"></script>
</head>

<body>
  <div id="app">

    <input type="text" v-model="phone">
    <span>{{phoneTip}}</span>

  </div>

  <script>

    new Vue({
      el: '#app',
      data: {
        phone: '13252125121',
        phoneTip: ''
      },
      // 观察data数据源中  phone 属性值的变化,它的值一但改变,则对应处理一些动作
      watch: {
        // 函数名称和data中的属性名称是一致的
        // 参1:新值
        // 参2:旧值
        phone(newValue, oldValue) {
          if (!/^1[3-9]\d{9}$/.test(newValue)) {
            this.phoneTip = '手机号码不合法'
          } else {
            this.phoneTip = ''
          }
        }
      }
    })
  </script>
</body>

</html>